home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / fr_may92.zip / FR.ASM < prev    next >
Assembly Source File  |  1992-05-04  |  13KB  |  422 lines

  1. ; FR.ASM --- TSR source for frequency logger.
  2. ;
  3. ;make file with turbo asm and linker:
  4. ;tasm fr.asm,,nul,nul;
  5. ;tlink /t fr,,nul,;
  6. ;
  7. ; make file with masm, link, exe2bin:
  8. ; masm fr.asm,,nul,nul;
  9. ; link fr,,nul,;
  10. ; exe2bin fr.exe fr.com
  11. ; del fr.exe
  12. ;
  13. ;Purpose: Maintains last access date and time for all files opened
  14. ;         by DOS call 3dh by logging the file name to file \freq.dat.
  15. ;
  16. ;Use:     Start FR.COM. The file \FREQ.DAT will be created if it does not
  17. ;         yet exist. File names are appended to the end of the file. The
  18. ;         collection file can be deleted, examined, etc, at any time.
  19. ;         The dump file name can be changed by a patch in debug: lots of
  20. ;         space is provided. At present, the TSR cannot de-install itself
  21. ;         but it does detect its own presence.
  22. ;
  23. ;Version: 17 Jan 1992 [prev: 1 December 1991]
  24. ;Authors: Grant B. Gustafson and Greg Conner.
  25. ;         Other authors will be added here as contributions are made.
  26. ;email:   gustafso@math.utah.edu, conner@math.utah.edu (Internet addresses)
  27. ;Copyright:
  28. ;         The source code is jointly owned by the authors. It may be used
  29. ;         for educational purposes without limitation. Modified versions
  30. ;         of the sources are considered private copies and should bear
  31. ;         the new authors names but not the present authors names.
  32. ;Responsibility:
  33. ;         This computer program is used at your own risk. If you use it,
  34. ;         then you assume responsibility for anything that happens as a
  35. ;         result of the program operation, including but not limited to
  36. ;         programming errors, faulty operation, file system destruction.
  37. ;         The authors are not responsible.
  38. ;
  39. Cseg      segment public para
  40.           assume  cs:Cseg, ds:nothing, es:nothing, ss:nothing
  41.  
  42.           org     080H
  43. cmdline   label   byte                 ;pointer to command line
  44.  
  45.           org     100H
  46. comentry: jmp     init
  47.  
  48.  
  49. ;previous interrupt handlers
  50.         even
  51. dos_int        label dword
  52. old21          dw 2 dup (?)            ;old int21 vector
  53. ;***********************************************************************
  54. ;interrupt handler for int21
  55. newint21 proc  near
  56.          assume ds:nothing
  57.         pushf                  ;save flags
  58.         push    si
  59.         mov     si,offset fn            ;are we to ignore updates?
  60.         cmp     byte ptr cs:[si],1
  61.         pop     si
  62.         jne     ex21
  63.         cmp     ax,'fr'                 ;check for install twice
  64.         jne     ex20
  65.         popf                            ;tried to install twice
  66.         xor     ax,ax                   ;clear flags
  67.         mov     ax,'co'                 ;return code for install
  68.         iret                            ;return from interrupt
  69. ex20:
  70.         cmp     ah,3dh
  71.         jne    ex21
  72.         call   update                   ;update dir entry
  73. ex21:   popf
  74.         jmp    (dos_int)                ;transfer to previous int21 vector
  75. newint21 endp
  76.  
  77. ;******************************************************************************
  78. ;resident data section follows
  79. ;******************************************************************************
  80.  
  81.  
  82.         even
  83. ;temporary stack used by interrupt handler
  84. newss          dw      0               ;segment of our temporary stack
  85. newsp          dw      0               ;initial stack pointer
  86.  
  87. ;information saved about the calling program
  88. oldss          dw      ?               ;stack segment
  89. oldsp          dw      ?               ;stack pointer
  90.  
  91.  
  92. ;***********************************************************************
  93. ;
  94.  
  95. update proc  near
  96.        assume ds:nothing
  97.  
  98. ;save current stack
  99.        mov     oldss,ss
  100.        mov     oldsp,sp
  101.  
  102. ;switch to our stack
  103.        cli
  104.        mov     ss,newss
  105.        mov     sp,newsp
  106.        sti
  107.  
  108. ;store registers
  109.        push    ax
  110.        push    bx
  111.        push    cx
  112.        push    si
  113.        push    di
  114.        push    es
  115.        push    dx
  116.        push    ds
  117.  
  118.         call    mungfile                ;full path name needed
  119.         call    openfile                ;open existent file c:\FREQ.DAT
  120.         cmp     ax,0                    ;returns 0 if file not open
  121.         jz      quit
  122.         call    seekend                 ;seek to end of file
  123.         call    writefile               ;write string to file
  124.         call    closefile               ;close c:\FREQ.DAT
  125. quit:
  126. ;restore registers
  127.        pop     ds
  128.        pop     dx
  129.        pop     es
  130.        pop     di
  131.        pop     si
  132.        pop     cx
  133.        pop     bx
  134.        pop     ax
  135.  
  136. ;restore stack
  137.        cli
  138.        mov     ss,oldss
  139.        mov     sp,oldsp
  140.        sti
  141.  
  142.        ret
  143. update endp
  144.  
  145. mungfile proc near
  146. ;copy file name, fix path name to give disk and directory
  147.         assume ds:nothing
  148.         mov     ax,ds
  149.         mov     es,ax
  150.         mov     di,dx                           ;es:di=source string
  151.         mov     ax,cs
  152.         mov     ds,ax
  153.         mov     si,offset path                  ;ds:si=dest string
  154. ; check for ':' at position 2 of string
  155.         mov     al,byte ptr es:[di]
  156.         cmp     al,0
  157.         je      loop1exit
  158.         inc     di
  159.         mov     ah,byte ptr es:[di]
  160.         dec     di
  161.         cmp     ah,':'                          ;drive spec present?
  162.         jne     loop1exit                       ;not found
  163.         inc     di
  164.         inc     di
  165.         jmp     loop1success
  166. loop1exit:                                      ;no ':' found
  167. ; look up the default drive number
  168.         mov     ah,19h
  169.         int     21h
  170.         add     al,'A'                          ;convert to letter
  171. loop1success:                                   ;found ':'
  172.         mov     bl,al                           ;save drive letter
  173.         mov     byte ptr ds:[si],al
  174.         inc     si
  175.         mov     byte ptr ds:[si],':'
  176.         inc     si
  177.         push    di
  178. ; check for '/' or '\' in source string
  179.         mov     al,byte ptr es:[di]
  180.         cmp     al,'\'
  181.         je      loop2success
  182.         cmp     al,'/'
  183.         je      loop2success
  184. getdefault:
  185. ;can't find delimiter, so look up default directory
  186.         mov     byte ptr ds:[si],'\'            ;need delimiter
  187.         inc     si
  188.         mov     dl,bl                           ;bl=drive letter
  189.         sub     dl,'A'
  190.         add     dl,1
  191. ;       mov     ds,buffer segment
  192. ;       mov     si,buffer offset
  193.         push    si
  194.         mov     ah,47h                          ;get current dir name
  195.         int     21h
  196.         pop     si
  197.         jnc     loop3
  198.         dec     si
  199.         mov     byte ptr ds:[si],0
  200. loop3:
  201.         cmp     byte ptr ds:[si],0              ;advance past default
  202.         je      loop2success                    ;dir name
  203.         inc     si
  204.         jmp     loop3
  205. loop2success:
  206.         pop     di
  207.         dec     si
  208.         cmp     byte ptr ds:[si],'\'            ;delimiter already?
  209.         je      loop35                          ;then skip it
  210.         inc     si
  211. loop35:
  212.         mov     al,byte ptr es:[di]
  213.         cmp     al,'\'                          ;start with '\'?
  214.         je      loop4
  215.         cmp     al,'/'                          ;start with '/'?
  216.         je      loop4
  217.         mov     byte ptr ds:[si],'\'            ;no, then put in delimiter
  218.         inc     si                              ;(but not two consecutive)
  219. loop4:
  220.         mov     al,byte ptr es:[di]             ;get source byte
  221.         mov     byte ptr ds:[si],al             ;put dest byte
  222.         cmp     al,0
  223.         je      loop5
  224.         inc     si
  225.         inc     di
  226.         jmp     loop4                           ;loop until copied
  227. loop5:
  228.         mov     byte ptr ds:[si],13             ;put dest byte
  229.         inc     si
  230.         mov     byte ptr ds:[si],10             ;put dest byte
  231.         inc     si
  232.         mov     byte ptr ds:[si],0              ;put dest byte
  233.         ret
  234. mungfile endp
  235.  
  236. openfile proc near
  237. ; FILEN=filename
  238. ; Open file. Create it if missing.
  239.  
  240.         assume ds:nothing
  241. ; open the file
  242.         mov     ax,cs
  243.         mov     ds,ax